package com.zlm.common.enums;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 打卡状态
 * @Author: duyufu
 * @Date: 2019/5/29 11:23
 */
public enum PunchStatusEnum {

    PUNCH_STATUS_NO_PUNCH(-1,"未打卡"),
    PUNCH_STATUS_0(0,"正常"),
    PUNCH_STATUS_1(1,"迟到"),
    PUNCH_STATUS_2(2,"早退");

    private int code;
    private String name;

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    private PunchStatusEnum(int code, String name) {
        this.code = code;
        this.name = name;
    }

    public static List<Map<String, Object>> getList() {
        List<Map<String, Object>> list = new ArrayList<>();
        Map<String, Object> map;
        for (PunchStatusEnum value : PunchStatusEnum.values()) {
            map = new HashMap();
            map.put("code", value.getCode());
            map.put("name", value.getName());
            list.add(map);
        }
        return list;
    }

    public static String getJsonString() {
        StringBuilder sb = new StringBuilder("{");
        for (PunchStatusEnum value : PunchStatusEnum.values()) {
            sb.append("\"" + value.getCode() + "\":\"" + value.getName() + "\",");
        }
        String json = sb.substring(0, sb.length() - 1) + "}";
        return json;
    }

    public static String getNameByCode(int code) {
        for (PunchStatusEnum value : PunchStatusEnum.values()) {
            if (value.code == code) {
                return value.name;
            }
        }
        return "";
    }

    public static int getCodeByName(String name) {
        for (PunchStatusEnum value : PunchStatusEnum.values()) {
            if (value.name == name) {
                return value.code;
            }
        }
        return 1;
    }

    @Override
    public String toString() {
        return "[code=" + code + ", name=" + name + "]";
    }
}
